/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.repository.repository.nestedrepository;


import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import com.inspur.edp.caf.generator.field.FieldGenerator;
import com.inspur.edp.caf.generator.item.ClassGenerator;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.overall.GeneratorUtil;
import com.inspur.edp.cef.generator.repository.RepositoryGenContext;
import com.inspur.edp.cef.generator.repository.RepositoryGenUtil;
import com.inspur.edp.cef.generator.repository.common.IntermediateType;
import com.inspur.edp.cef.generator.repository.repository.field.DacFieldGenerator;
import com.inspur.edp.cef.generator.repository.repository.method.GetDacMethodGenerator;
import org.eclipse.jdt.core.dom.Modifier;

import java.util.ArrayList;

public class DataTypeRepositoryGenerator extends ClassGenerator
{
	private static final String DacFieldName = "mainDac";
	protected RepositoryGenContext parentContext;

//ORIGINAL LINE: protected internal new DataTypeReposGenContext Context => (DataTypeReposGenContext)super.Context;
	protected DataTypeReposGenContext getDataTypeRepoGenContext(){return (DataTypeReposGenContext)super.getContext();}
	public DataTypeRepositoryGenerator(RepositoryGenContext parentContext)
	{
		super(parentContext.getCefContext().getCefGenContext().getCoreGenContext().getCompilationUnitInfo());
		this.parentContext = parentContext;
		parentContext.getCefContext().setRepositoryType(new MediateType(getNameSpace(),getName()));
	}

	@Override
	protected ClassGeneratorContext createClassInfoContext()
	{
		DataTypeReposGenContext context = getDataTypeRepoGenCtx();
		context.setCefContext(parentContext.getCefContext());
		context.setAssemblerInfo(parentContext.getAssemblerInfo());
		return context;
	}

	protected DataTypeReposGenContext getDataTypeRepoGenCtx()
	{
		return new DataTypeReposGenContext();
	}

	@Override
	protected ArrayList<Modifier.ModifierKeyword> getAccessModifier() {
		ArrayList<Modifier.ModifierKeyword> list =new ArrayList<>();
		list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
		return list;
	}

	@Override
	protected java.util.ArrayList<FieldGenerator> createFieldGenerator()
	{
		java.util.ArrayList<FieldGenerator> fieldGens = new java.util.ArrayList<FieldGenerator>();
		DacFieldGenerator dacFieldGen = gerDacFieldGenerator();
		fieldGens.add(dacFieldGen);

		return fieldGens;
	}

	@Override
	protected java.util.ArrayList<ClassMethodGenerator> createMethodGenerators()
	{
		java.util.ArrayList<ClassMethodGenerator> methodGens = new java.util.ArrayList<ClassMethodGenerator>();
		//① getDac();
		GetDacMethodGenerator dacGen = getDacMethodGenerator();
		methodGens.add(dacGen);

		return methodGens;
	}

	protected GetDacMethodGenerator getDacMethodGenerator()
	{
		return new GetDacMethodGenerator(DacFieldName,getDataTypeRepoGenContext());
	}

	protected final DacFieldGenerator gerDacFieldGenerator()
	{
		return new DacFieldGenerator(DacFieldName);
	}

	protected String getNameSpace()
	{
		return parentContext.getCefContext().getNameSpace();
	}

	@Override
	protected String getName()
	{
		if(this.parentContext.getCefContext().getCefGenContext().getCommonDataType() instanceof GspBizEntityObject){
			return ((GspBizEntityObject)this.parentContext.getCefContext().getCefGenContext().getCommonDataType()).getBelongModel().getCode() + "Repository";
		}
//		((GspBizEntityObject)this.parentContext.getCefContext().getCefGenContext().getCommonDataType()).getBelongModel().getCode();
		return parentContext.getCefContext().getCefGenContext().getCommonDataType().getCode() + "Repository";
	}
}
